// Set the number of sides for the vase (higher number results in a smoother surface)
$fn = 100;

// Define the main vase parameters
vase_height = 150; // Height of the vase
vase_bottom_radius = 30; // Radius of the bottom of the vase
vase_top_radius = 50; // Radius of the top of the vase
vase_thickness = 3; // Thickness of the vase walls

// Define the decorative parameters
num_twists = 3; // Number of twists along the vase
twist_height = vase_height / num_twists; // Height of each twist
petal_count = 12; // Number of petals around the vase
petal_size_min = 8; // Minimum size of petals
petal_size_max = 15; // Maximum size of petals
wave_amplitude = 5; // Amplitude of the wavy top edge
base_height = 20; // Height of the decorative base
base_radius = vase_bottom_radius + 10; // Radius of the decorative base

// Create the twisted vase shape
module twisted_vase() {
    linear_extrude(height = vase_height, twist = 360 * num_twists, scale = [vase_top_radius / vase_bottom_radius, 1]) {
        circle(r = vase_bottom_radius);
    }
}

// Create a petal shape with varying sizes
module petal(size) {
    resize([size, size, size / 2]) {
        sphere(r = 1);
    }
}

// Create a ring of petals around the vase with varying sizes
module petal_ring(height) {
    for (i = [0:petal_count-1]) {
        rotate([0, 0, i * 360 / petal_count]) {
            translate([vase_bottom_radius + (vase_top_radius - vase_bottom_radius) * height / vase_height, 0, height]) {
                petal(petal_size_min + (petal_size_max - petal_size_min) * i / (petal_count - 1));
            }
        }
    }
}

// Create a wavy top edge
module wavy_top() {
    rotate_extrude(angle = 360) {
        translate([vase_top_radius, 0, 0]) {
            circle(r = wave_amplitude);
        }
    }
}

// Create a decorative base
module decorative_base() {
    cylinder(h = base_height, r1 = base_radius, r2 = base_radius * 0.8);
}

// Create the final vase by combining the twisted vase, petals, wavy top, and base
module decorated_vase() {
    difference() {
        union() {
            twisted_vase();
            translate([0, 0, vase_height - wave_amplitude]) {
                wavy_top();
            }
            decorative_base();
        }
        translate([0, 0, vase_thickness]) {
            scale([0.95, 0.95, 1]) {
                twisted_vase();
            }
        }
    }
    
    for (i = [0:num_twists-1]) {
        petal_ring(i * twist_height);
    }
}

// Render the final decorated vase
decorated_vase();
